package Roboter;

import java.util.ArrayList;


import lejos.nxt.Button;
import lejos.nxt.ButtonListener;
import lejos.nxt.LCD;

public class Positionen {
	private ArrayList<Position> listePositionen;
	private LinearPoti linearPoti;
	private RotationsPoti rotationsPoti;
	private Linearachse linearachse;
	private int aktuellePosition;

	public Positionen(LinearPoti linearPoti, RotationsPoti rotationsPoti, Linearachse linearachse) {
		this.listePositionen = new ArrayList<Position>();
		this.linearPoti = linearPoti;
		this.rotationsPoti = rotationsPoti;
		this.linearachse = linearachse;
		this.aktuellePosition = 0;
		for (int i = 0; i < 3; i++) {
			this.aktuellePosition++;
			positionEinlesen();
		}
	}

	private void positionEinlesen() {
		Button.RIGHT.addButtonListener(new ButtonListener() {
			public void buttonReleased(Button arg0) {
				linearachse.stopp();
			}
			public void buttonPressed(Button arg0) {
				linearachse.langsamVor();
			}
		});
		
		Button.LEFT.addButtonListener(new ButtonListener() {
			public void buttonReleased(Button arg0) {
				linearachse.stopp();
			}
			public void buttonPressed(Button arg0) {
				linearachse.langsamZurueck();
			}
		});
		
		System.out.println("Teach-In " + this.aktuellePosition + ":");
		System.out.println("[Enter]");
		Button.ENTER.waitForPress();
		LCD.clear();
		if (this.aktuellePosition < 3)
			listePositionen.add(new Position(this.linearPoti.gibAktuellenWert(), this.rotationsPoti.gibAktuellenWert(), true));
		else
			listePositionen.add(new Position(this.linearPoti.gibAktuellenWert(), this.rotationsPoti.gibAktuellenWert(), false));
	}
	
	public Position gibPosition1() {
		return listePositionen.get(0);
	}
	
	public Position gibPosition2() {
		return listePositionen.get(1);
	}
	
	public Position gibPosition3() {
		return listePositionen.get(2);
	}
}
